package com.paipaideli;

import android.app.Application;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Environment;
import android.view.WindowManager;

import com.paipaideli.common.utils.CrashHandlerUtil;
import com.paipaideli.common.utils.preferrnces.FastData;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.socialize.PlatformConfig;
import com.umeng.commonsdk.UMConfigure;

import java.io.File;
import java.io.IOException;

public class MyApplication extends Application {

    private static MyApplication instance;
    public static int isHome; //0 //1 //2 //3
    public static int isAlipay; //哪个页面进入支付 0 我的资产  1 拍场

    public static MyApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        instance = this;
        //注册存储数据的
        FastData.getInstance();

//        if (!BuildConfig.DEBUG) {
            CrashHandlerUtil crashHandler = CrashHandlerUtil.getInstance();
            crashHandler.init(getApplicationContext());
//        }

        CrashReport.initCrashReport(getApplicationContext(), "859c0fef1c", true);
        UMConfigure.init(this, "583e2469f5ade476b6001421", "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
        PlatformConfig.setWeixin("wxf90fd221278b8b0f", "d32bc0018da73897655c6d1f7b298a3c");
        //PlatformConfig.setWeixin("wxf90fd221278b8b0f", "f4be322c17d64acac3a5805752a1dc9d");
        PlatformConfig.setQQZone("1105681816", "rcXx9p3oKDlf48bY");

    }

    public static MyApplication getInstanse() {
        if (instance == null) {
            throw new RuntimeException("获取Application 对象为空，这是千古奇闻，这居然发生了。");
        }
        return instance;
    }

    public String getAppCacheDir() throws IOException {
        File file = getExternalCacheDir();
        if (file != null) {
            return file.getAbsolutePath();
        }
        File sdDir = Environment.getExternalStorageDirectory();
        if (sdDir != null) {
            File f = new File(sdDir.getAbsolutePath() + "/.paipaideli");
            if (!f.exists()) {
                f.mkdirs();
            }
            return f.getAbsolutePath();
        }

        File downloadCacheDir = Environment.getDownloadCacheDirectory();
        if (downloadCacheDir != null) {
            return downloadCacheDir.getAbsolutePath();
        }
        throw new IOException("没有可用于存储临时文件的目录");
    }
}
